<?php

	if(!defined('YMT')) exit;

	require_once 'Mailer.class.php';
	require_once 'Smtp.class.php';

	/**
	 * @package Yomm
	 * @author bsuter
	 *
	 */
	Class Yomm_Mail_Send Extends PHPMailer
	{
		
		public $error = null;
		
		public function __construct($mail, $fullname, $subject, $text)
		{
			// overwrite default PHPMailer values.
			$this->SetFrom(SiteConfig::MailSenderMail, SiteConfig::MailSenderName); 
  			$this->Host = SiteConfig::MailSmtpHost;
			$this->Port = SiteConfig::MailPort;
			$this->Helo = "localhost.localdomain";
			$this->SMTPAuth = true;
			$this->Username = SiteConfig::MailSmtpUser;
			$this->Password = SiteConfig::MailSmtpPass;
			$this->IsHTML(TRUE);
    		$this->IsSMTP();
    		
    		// send propertys
    		$this->AddAddress($mail, $fullname);	
			$this->Subject = $subject;
			$this->AltBody = "To view the message, please use an HTML compatible email viewer!";
			//$this->MsgHTML(eregi_replace("[\], '', $text));
			$this->MsgHTML($text); // TODO: fix this with \ replacement	
		}
		
		public function submit()
		{
			if(!$this->Send()) {
				$this->error = $this->ErrorInfo;
				throw new Yomm_Error('There was an error by sending email to "' . $user_mail . '". err info: '.$this->error);
			}
		}
		/*
		public function writeAnonym($user_mail, $user_name, $subject, $text)
		{
			$this->AddAddress($user_mail, $user_name);	
			
			$this->Subject = $subject;
			
			$this->AltBody = "To view the message, please use an HTML compatible email viewer!";
			
			
			//$this->MsgHTML(eregi_replace("[\], '', $text));
		
			$this->MsgHTML($text); // TODO: fix this with \ replacement
			
			if(!$this->Send()) {
				$this->error = $this->ErrorInfo;
				throw new Yomm_Error('There was an error by sending email to "' . $user_mail . '". err info: '.$this->error);
				return false;
			}
			
			return true;
		}
		*/
		
	}